home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Gamer Resource Kit / Hardcore Gamer Resource Kit - Disc 3.iso / screensavers / saver17.zip / VoodooLights / Sources / win.c < prev    next >
C/C++ Source or Header  |  1997-07-24  |  4KB  |  181 lines

  1. /*------------------------------------------------------/
  2. /                                                        /
  3. /    Copyright 1997, SΘrgio Durte <smd@di.fct.unl.pt>    /
  4. /                                                        /
  5. /------------------------------------------------------*/
  6.  
  7.  
  8. #include <windows.h>
  9. #include <glide.h>
  10.  
  11. #include "defines.h"
  12. #include "win.h"
  13. #include "defines.h"
  14. #include "hw.h"
  15. #include "mat.h"
  16. #include "cam.h"
  17.  
  18. static HINSTANCE hInstance ;
  19. static HWND hwnd ;
  20.  
  21. static char szAppName[] = "Voodoo Lights Screensaver Demo";
  22.  
  23. extern Float Time ;
  24.  
  25. static int ypos = 0;
  26.  
  27.  
  28. static DEVMODE devmode ;
  29. static DWORD dwCurrWidth, dwCurrHeight, dwCurrBPP ;
  30.  
  31. static void win_RestoreDisplay( void )
  32. {
  33.     devmode.dmSize = sizeof(DEVMODE);
  34.     devmode.dmBitsPerPel = dwCurrBPP;
  35.     devmode.dmPelsWidth = dwCurrWidth;
  36.     devmode.dmPelsHeight = dwCurrHeight;
  37.     devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT ;
  38.     ChangeDisplaySettings(& devmode, 0 ) ;
  39. }
  40. static void win_ResizeDisplay( void )
  41. {
  42.  
  43.     HWND           hDesktop;
  44.     HDC            hDCDesk;
  45.  
  46.     hDesktop = GetDesktopWindow() ;
  47.     hDCDesk = GetDC( hDesktop ) ;
  48.     
  49.     dwCurrWidth = GetDeviceCaps( hDCDesk, HORZRES ) ;
  50.     dwCurrHeight = GetDeviceCaps( hDCDesk, VERTRES ) ;
  51.     dwCurrBPP = GetDeviceCaps( hDCDesk, BITSPIXEL);
  52.  
  53.     ReleaseDC( hDesktop, hDCDesk ) ;
  54.  
  55.     devmode.dmSize = sizeof(DEVMODE);
  56.     devmode.dmPelsWidth = hw_ResX ;        
  57.     devmode.dmPelsHeight = hw_ResY ; 
  58.     devmode.dmBitsPerPel = 16 ;    
  59.     devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
  60.     ChangeDisplaySettings( & devmode, 0 ) ;
  61. }
  62.  
  63. void win_printf(char *msg)
  64. {
  65.     HDC hdc = GetDC( hwnd ) ;
  66.     TextOut( hdc, 0, ypos, msg, strlen( msg ) ) ;
  67.     ypos = (ypos + 16) % (45*16);
  68.     ReleaseDC( hwnd, hdc ) ;
  69. }
  70.  
  71. static LRESULT CALLBACK win_EventHandler(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  72. {
  73.     switch (iMsg) {
  74.         case WM_KILLFOCUS:
  75.         case WM_SETFOCUS :
  76.         case WM_MOUSEMOVE:
  77.         case WM_CHAR:    
  78.             if( Time > 2.0 ) PostQuitMessage( 0 ) ;
  79.             return 0;
  80.         case WM_DESTROY:
  81.             PostQuitMessage( 0 );
  82.             break ;
  83.     }
  84.     return( DefWindowProc(hwnd, iMsg, wParam, lParam) ) ;
  85. }
  86.  
  87.  
  88. static void win_DestroyWindow()
  89. {
  90.     hw_ShutdownHardware() ;
  91.     DestroyWindow(hwnd) ;
  92.     win_RestoreDisplay() ;
  93. }
  94.  
  95. HWND win_StartWindow(HINSTANCE hInstance, int iCmdShow)
  96. {
  97.     HWND        w;
  98.     WNDCLASSEX    wc;
  99.  
  100.     wc.cbSize        = sizeof( wc ) ;
  101.     wc.style         = CS_HREDRAW | CS_VREDRAW ;
  102.     wc.lpfnWndProc   = win_EventHandler ;
  103.     wc.cbClsExtra    = 0 ;
  104.     wc.cbWndExtra    = 0 ;
  105.     wc.hInstance     = hInstance ;
  106.     wc.hIcon         = LoadIcon(hInstance, IDI_APPLICATION) ;
  107.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW) ;
  108.     wc.hbrBackground = GetStockObject(DKGRAY_BRUSH) ;
  109.     wc.lpszMenuName  = NULL ;
  110.     wc.lpszClassName = szAppName ;
  111.     wc.hIconSm       = LoadIcon(hInstance, IDI_APPLICATION) ;
  112.  
  113.     RegisterClassEx( & wc ) ;
  114.     
  115.     w = CreateWindowEx(
  116.         WS_EX_DLGMODALFRAME,                            
  117.         szAppName,
  118.         szAppName,
  119.         WS_CAPTION,        
  120.         0,
  121.         0,
  122.         hw_ResX,
  123.         hw_ResY,
  124.         NULL,
  125.         NULL,
  126.         hInstance,
  127.         NULL );    
  128.     ShowWindow( w, SW_SHOWMAXIMIZED );
  129.     UpdateWindow( w );
  130.  
  131.  
  132.     SetCapture( w ) ; // Falta um ReleaseCapture algures
  133.  
  134.     return(w);
  135. }
  136.  
  137. void win_MessageBox( Bool Fatal, char *Title, char *Body )
  138. {
  139.     ShowCursor( True ) ;
  140.     MessageBox(hInstance, Body, Title, MB_OK);
  141.     win_DestroyWindow() ;
  142.     if( Fatal ) exit(-1) ;
  143. }    
  144.  
  145.  
  146. static int win_PeekMessages( void )
  147. {
  148.     MSG msg;
  149.  
  150.     while (PeekMessage(& msg, NULL, 0, 0, PM_REMOVE)) {
  151.         if (msg.message == WM_QUIT) 
  152.             return msg.wParam ;
  153.         TranslateMessage( & msg ) ;
  154.         DispatchMessage( & msg ) ;
  155.     }
  156.     return 1 ;
  157. }
  158.  
  159.  
  160. int WINAPI WinMain(HINSTANCE hI, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
  161. {
  162.  
  163.     if( szCmdLine && szCmdLine[1] == 'p' ) return 0 ;
  164.  
  165.     hInstance = hI ;
  166.  
  167.     win_ResizeDisplay() ;
  168.  
  169.     hwnd = win_StartWindow(hInstance, iCmdShow);
  170.     ShowCursor( False ) ;
  171.  
  172.     main_InitModule() ;
  173.  
  174.     while( win_PeekMessages() ) main_MainLoop() ;
  175.  
  176.  
  177.     win_DestroyWindow() ;
  178.  
  179.     return 0 ;
  180. }
  181.